//==================================================================
//  Copyright (C) 2006-2007  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
/// @file
///
///
/// 
/// @author Davide Pasca
/// 
//==================================================================

#ifndef REND_TARGET_H
#define	REND_TARGET_H

#include "psys.h"
#include "texture_base.h"

//==================================================================
class RendDevice;

//==================================================================
class RendTarget
{
	RendDevice *_rdevicep;

	u_int		_fb;				// color render target
	u_int		_depth_rb;			// depth render target
	u_int		_stencil_rb;		// depth render target
	u_int		_color_tex_id;				// texture
	u_int		_depth_tex_id;		
	int			_w, _h;
	TextureBase	_color_tex;
	TextureBase	_depth_tex;

public:
	//==================================================================
	class CreationParams
	{
	public:
		bool	CREATE_COLOR_BUFFER;
		bool	CREATE_DEPTH_BUFFER;
	
	public:
		CreationParams() :
		  CREATE_COLOR_BUFFER(true),
		  CREATE_DEPTH_BUFFER(true)
		{
		}
	};

public:
	RendTarget( u_int w, u_int h, const CreationParams &params, RendDevice *rdevicep );
	~RendTarget()
	{
		freeAll();
	}

	void	BeginDestination();
	void	EndDestination();
	void	SelectTexture();
	u_int	GetWidth() const { return _w; }
	u_int	GetHeight() const { return _h; }

	TextureBase	&GetColorTexture()
	{
		return _color_tex;
	}

	TextureBase	&GetDepthTexture()
	{
		return _depth_tex;
	}

private:
	void	freeAll();
	void	myGlErrorCheck();
};

#endif